#include("/common/layout/bootstrap_form_layout.html")
#@layout()
#define title()
#(jxrb.message(actionName,"systemMenu"))
#end
#define head()
#modeltag({tagcode:"jxbrms_systemmenu",term:"menu_id=?",id:params[0]})
#jx_js({file:"sea.js"})
<script>
  seajs.use(['jquery', 'jx_msgbox', "action_tree", "jac", "jx_check"], function ($, msgbox, at) {
    $("#b_submit").on("click", function () {

      if (!jxCheck.check()) {
        return false;
      }
      var action = "added";
      if ($("#menu_id").val() == "") {
        action = "added";
      } else {
        action = "edited";
      }
      msgbox.confirm({url: "#(controllerKey)" + action + "/"},
      function ()
      {
        msgbox.close();
        if (msgbox.messageType != 2) {
          window.parent.refreshTree($("#parentId").val());
          clearForm();
        }
      }, function ()
      {
        if (msgbox.messageType != 2)
          returnInfo();
        window.parent.refreshTree($("#parentId").val());
      });
    })
    var action = '#(action)';
    function clearForm()
    {
      if (action == 'added')
      {
        $("#viewNum").val(parseInt($("#viewNum").val()) + 1);
        $("#menuName").val("");
        $("#title").val("");
        $("#target").val("");
      }
    }

    $(function ()
    {
      if (action == "added") {
        at.setViewNum('#(systemmenu.parent_id ??)');
      }
    });
    function changeMenu()
    {
      at.setViewNum($("#parentId").val());
    }

    $("#b_return").on("click", function () {
      if (action == 'added') {
        location.href = "#(backurl)";
      } else {
        returnInfo()
      }
    });

    function returnInfo()
    {
      var parentId = $("#parentId").val();
      if (parentId == "") {
        location.href = "#(controllerKey)1-1"
      } else {
        location.href = "#(controllerKey)2-" + parentId;
      }
    }

    window.changeMenu = changeMenu;
  });

</script>



#end

#define form()
#include("info.html")
#end


#define formAfter()
<center>
  #jx_button({value:"action.save",class:"btn btn-primary"})&nbsp;&nbsp;&nbsp;&nbsp;
  #jx_button({value:"action.return",id:"b_return",class:"btn btn-danger"})
</center>
#end
